<template>
	<u-cell-group>
		<u-cell-item icon="setting-fill" title="环境地址" :value="appDebug ? '测试' : '线上'" @click="show = true"></u-cell-item>
		
		<u-action-sheet :list="list" @click="click" v-model="show" :cancel-btn="true"></u-action-sheet>
	</u-cell-group>
</template>

<script>
	import { mapState } from 'vuex'
	export default {
		data() {
			return {
				list: [{
					text: '线上',
				},{
					text: '测试',
				}],
				show: false,
				
				appDebug: false
			}
		},
		computed: {
			...mapState({
				appType: state => state.app.appType
			})
		},
		onLoad() {
			this.appDebug = uni.getStorageSync('appDebug');
		},
		methods: {
			click(index) {
				console.log(index)
				uni.showLoading({})
				const appDebug = index === 0 ? false : true
				uni.setStorage({
					key: 'appDebug',
					data: appDebug,
					success: (res)=> {
						this.$store.commit('app/switchAppType', this.appType);
						this.$u.toast('设置成功')
						this.$store.commit('user/logout');
						uni.reLaunch({
							url: '/pages/login',
							success() {
								
							},
							fail() {
								
							},
						})
					},
					complete: () => {
						uni.hideLoading()
					}
				})
			}
		}
	}
</script>

<style>

</style>
